<template>
  <div class="search">
    <el-autocomplete @select="goDetail" :trigger-on-focus="false" clearable placeholder="请你输入医院名称" v-model="hosname"
      :fetch-suggestions="fetchData" />
    <el-button type="primary" size="default" :icon="Search">搜索</el-button>
  </div>
</template>

<script setup lang="ts">
//引入element-plus提供图标
import { Search } from "@element-plus/icons-vue";
import { ref } from "vue";
import { useRouter } from "vue-router";
//引入请求方法
import { reqHospitalInfo } from "@/api/home";
import type { HospitalInfo } from "@/api/home/type";
const $router = useRouter()
const hosname = ref<string>('')

const fetchData = async (keyword: string, cb: any) => {
  const res: HospitalInfo = await reqHospitalInfo(keyword)
  const showData = res.data.map(item => {
    return {
      value: item.hosname,
      hoscode: item.hoscode
    }
  })
  cb(showData)
}
const goDetail = (item: any) => {
  $router.push({ path: '/hospital/register', query: { hoscode: item.hoscode } })
}
</script>
<script lang="ts">
export default {
  name: "Search",
};
</script>

<style scoped lang="scss">
//深度选择器:>>>  /deep/ ::v-deep
.search {
  width: 100%;
  height: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 10px 0px;

  ::v-deep(.el-input__wrapper) {
    width: 600px;
    margin-right: 10px;
  }
}
</style>
